package com.boot.dongli.dlxLength;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author: lkz
 * @Title: LenProMsg
 * @Description: 消息队列长度 测试
 * @Date: 2023/10/16 15:47
 */
@Component
@Slf4j
public class LenProMsg {



    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 先进入队列的消息会变成信息队列
     */
    public void sendMsg(){
        for (int i = 1; i <= 8; i++) {
            String str="hello world " + i;
            Message message= MessageBuilder.withBody(str.getBytes())
                    .build();
            rabbitTemplate.convertAndSend("length.normal.exchange","length.normal",message);
        }

        log.info("消息发送完毕：发送时间为：{}",new Date());
    }

}
